package org.aceor.mddal.gateway.merger.groupby;

import org.aceor.mddal.gateway.merger.common.AbstractMergerInvokeHandler;
import org.aceor.mddal.gateway.merger.common.ResultSetQueryIndex;
import org.aceor.mddal.gateway.resultset.GroupByResultSet;
import org.aceor.mddal.gateway.util.ResultSetUtil;

import java.lang.reflect.Method;
import java.sql.SQLException;

/**
 * Created by lxue on 16/4/17.
 */
public class GroupByInvokeHandler extends AbstractMergerInvokeHandler<GroupByResultSet> {

    public GroupByInvokeHandler(final GroupByResultSet groupByResultSet) {
        super(groupByResultSet);
    }

    @Override
    protected Object doMerge(final GroupByResultSet groupByResultSet, final Method method, final ResultSetQueryIndex resultSetQueryIndex) throws ReflectiveOperationException, SQLException {
        return ResultSetUtil.convertValue(
                groupByResultSet.getCurrentGroupByResultSet().getValue(resultSetQueryIndex),
                method.getReturnType());
    }
}
